function msg = f4d(img, seed)
    % F4D  Extract message using F4.
    
    r = int16(im2vec(img, [8 8])');    
    [M,N] = size(r);
    bin = zeros(1,M*N);

    % generate pusedo random sequence.
    if nargin < 2
        seed = M*N;
    end
    rs = getRandStream(seed);
    tran = prand3(M*N, rs);

    % get all LSB
    count = 1;
    p = 0;
    for i1=1:M
        for j1=1:N
            p = p + 1;
            t = tran(1,p);% t=1..N*M
            i = floor((t-1) / N)+1;
            j = (t-1) - (i-1)*N + 1;
            if j == 1
                continue;
            end
            u = r(i, j);
            if (u ~= 0)
                if u > 0
                    bin(count) = mod(u,2);
                else
                    bin(count) = 1 - mod(u,2);
                end
                count = count + 1;
            end
        end
    end
    
    count = count - 1;
    
    % output
    msg = binaryToArray(bin, count);
    fprintf(1, 'recovered message is: %s\n',msg);
end
